# -*- coding=utf-8 -*-
from django.shortcuts import redirect
from django.views.generic import TemplateView

from .forms import CommentForm


class CommentView(TemplateView):
    http_method_names = ["post"]
    template_name = "comment/result.html"

    def post(self, request, *args, **kwargs):
        comment_from = CommentForm(request.POST)
        target = request.POST.get("target")

        if comment_from.is_valid():
            instance = comment_from.save(commit=False)
            instance.target = target
            instance.save()
            succeed = True
        else:
            succeed = False
        context = {
            "succeed": succeed,
            "form": comment_from,
            "target": target,
        }
        return self.render_to_response(context)
